import {
	find
} from "../../api/modules/find"

let emptyIndex = 1
let emptyIndexMax = 4
export const getCovers = (list) => {
	return new Promise((resolve, reject) => {
		let asyncQueue = []
		list.forEach((item, index) => {
			const asyncItem = find.unify.getPItemAndOnShelfCountAndDuxiuImageUrl({
					title: item.title,
					isbn: item.isbn,
					recordId: item.recordId
				})
				.then((data) => {
					let cover = data.duxiuImageUrl || require(
						`@/static/empty/index0${emptyIndex}.png`)
					emptyIndex = emptyIndex === emptyIndexMax ? 1 : emptyIndex + 1
					return Object.assign(item, {
						cover,
						coverEmpty: !data.duxiuImageUrl
					})
				})
			asyncQueue.push(asyncItem)
		})
		Promise.all(asyncQueue).then((list) => {
			resolve(list)
		})
	})

}